<script language="javascript">
function funEditUser(uid,cid,act)
{
	document.frmSubmit.txtAssRouteId.value = uid;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}
var ajax1=new sack();
function funDeleteAssignedGeo(id,cid)
{
	qry = "DELETE from tb_assigngeofence WHERE tag_clientId = "+cid+" and tri_id = "+id;
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
	//alert(ajax1.requestFile);
	ajax1.onCompletion = function(){
		
      if(ajax1.response)
	  {
		 alert("Status Updated Successfully.");
		 location.href='?ch=viewAssignGeo';
	  }
	  else
	  {
		  alert("Status Not Updated.");
	  }
		
	};
	ajax1.runAJAX();
}
function changeSts(id,span,uid)
{
	if(document.getElementById(id).checked)
		qry = "UPDATE tb_assigngeofence SET tri_status = 1 WHERE tri_id = "+uid;
	else
		qry = "UPDATE tb_assigngeofence SET tri_status = 0 WHERE tri_id = "+uid;
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
	//alert(ajax1.requestFile);
	ajax1.onCompletion = function(){resultUserStatus(span,document.getElementById(id).checked)};
	ajax1.runAJAX();
}
function resultUserStatus(span,flag)
{
	//alert(ajax1.response)
  if(ajax1.response)
  {
	 alert("Status Updated Successfully.");
	 if(flag) 
	  	document.getElementById(span).innerHTML = 'Deactive';
	 else 
		document.getElementById(span).innerHTML = 'Active';
  }
  else
  {
	  alert("Status Not Updated.");
  }
	
}
</script>
<div align="left" class="listofusers">&nbsp;<a href="#" onclick="location.href='?ch=assignRoute'">Add Route</a></div>
<div align="center">
<table class="gridform_final">
    <tr>
        <th width="2%">#   </th>
        <th width="20%">Route Name</th>
        <th width="15%">Device Name(s)</th>
        <th width="18%">Days</th> 
        <th width="10%">Pickup Time</th>
        <th width="10%">Drop Time</th>
        <th width="5%">Edit</th>
        <!--<th width="8%">Active</th>
        
        <th width="8%">Delete</th>-->
   </tr>
   <?php
   $sql = "SELECT * FROM tb_route_info,tb_deviceinfo WHERE di_id = tri_deviceId and tri_clientId  =".$_SESSION[clientID];
   $rows = $db->query($sql);
   if($db->affected_rows > 0)
   {
	$i = 0;
   	while ($record = $db->fetch_array($rows)) 
	{
		if($record[di_deviceName])
			$devName = $record[di_deviceName];
		else
			$devName = $record[di_deviceId];

		$dayArr = explode(",",$record[tri_alertDays]);
		
		$daysArr = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		if(count($dayArr) > 0 )
		{
			$days = '';
			for($v = 0; $v < count($dayArr)-1; $v++)
			{
				$days .= $daysArr[$dayArr[$v]].',';
			}
		}else $days = 'NA';
		
	?>
		<tr>
        <td><?php echo $i+1;?></td>
        <td><?php echo ucfirst($record[tri_routeName]);?></td>
        <td><?php echo ucfirst($devName);?></td>
        <td><?php echo $days;?> </td> 
        <td><?php echo str_replace("#"," - ",$record[tri_mornTripTime]);?> </td>
        <td><?php echo str_replace("#"," - ",$record[tri_evenTripTime]);?> </td>
       <!-- <td>
        <input type="checkbox" name="chkUsrStatus<?php echo $l;?>" id="chkUsrStatus<?php echo $l;?>" <?php if($record[tri_status] == 1) {?> checked="checked" <?php } ?> onclick="changeSts(this.id,'stsId<?php echo $i;?>','<?php echo $record[tri_id];?>')"/>
        <span id="stsId<?php echo $i;?>"><?php if($record[tri_status]) echo "Deactive"; else echo "Active"; ?></span>
        </td>-->
        <td><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[tri_id];?>','<?php echo $_SESSION[clientID];?>','?ch=assignRoute')" /></td>
        <!--<td><img src="../../images/delete.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funDeleteAssignedGeo('<?php echo $record[tri_id];?>','<?php echo $_SESSION[clientID];?>')" /></td>-->
   </tr>
    <?php
	$i++;
	}
	}
	else
	{
   ?>
		<tr>
        <td colspan="9"><span>Not data found</span></td>
   </tr>
   <?php
	}
   ?>
</table>
</div>
</div>
<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtAssRouteId" id="txtAssRouteId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
</form>